"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoomTemplateModel = void 0;
const GameConfig_1 = require("../../src/config/GameConfig");
const RoomTemplateDao_1 = require("../dao/RoomTemplateDao");
class RoomTemplateModel {
    static init() {
        return __awaiter(this, void 0, void 0, function* () {
            let rows = yield RoomTemplateDao_1.RoomTemplateDao.get_all_room_template();
            this.roomTemplateMap.clear();
            for (let i = 0; i < rows.length; i++) {
                this.initOneRoomTemplate(rows[i]);
            }
        });
    }
    static initOneRoomTemplate(obj) {
        let model = {
            id: obj.id,
            name: obj.name,
            gameType: obj.game_type,
            clubid: obj.clubid,
            creator: obj.creator,
            roomType: obj.roomType,
            roomConfigBase: JSON.parse(obj.conf_base),
        };
        if (model.gameType == GameConfig_1.GameConfig.Game_Type.Mj) {
            model.roomConfigMj = JSON.parse(obj.config_game);
        }
        this.roomTemplateMap.set(model.id, model);
        return model;
    }
    static getRoomTemplateListByClub(clubid) {
        let result = [];
        this.roomTemplateMap.forEach((model, key) => {
            if (model.clubid == clubid) {
                result.push(model);
            }
        });
        return result;
    }
    // public static getRoomTemplateByZiyou(level: number) {
    //     let result: Array<RoomTemplateModel> = []
    //     this.roomTemplateMap.forEach((model: RoomTemplateModel, key: number) => {
    //         if (model.roomType == RoomConfig.Room_Type.Ziyou) {
    //             // if(model.conf["level"] == level){
    //             //     result.push(model)
    //             // }
    //         }
    //     });
    //     return result;
    // }
    static deleteRoomTemplate(id) {
        this.roomTemplateMap.delete(id);
    }
}
exports.RoomTemplateModel = RoomTemplateModel;
RoomTemplateModel.roomTemplateMap = new Map();
